<template>
<h1>员工列表练习</h1>
  <input type="text" v-model="username" placeholder="请输入员工姓名">
  <input type="text" v-model="salary" placeholder="请输入员工工资">
  <input type="text" v-model="job" placeholder="请输入员工岗位">
  <button @click="add">点我添加</button>
  <hr>
  <table border="1">
    <thead>
    <tr>
      <th>编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>岗位</th>
    </tr>
    </thead>
    <!--  index须写在item之后  -->
    <tr v-for="(item,index) in employee_arr">
      <td>{{index+1}}</td>
      <td>{{item.username}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>
    </tr>

  </table>
</template>
<script setup>
import {ref} from "vue";

const username = ref('')
const salary = ref('')
const job = ref('')
const employee_arr = ref([])
const add = ()=>{
  /*添加之前判断*/
  if(username.value.trim()==''||salary.value.trim()==''||job.value.trim()==''){
    alert('输入不能为空');
    return;

  }
  employee_arr.value.push({
    username:username.value,
    salary:salary.value,
    job:job.value
  })
  username.value='';
  salary.value='';
  job.value='';
}
</script>


<style scoped>

</style>